<template>
  <main class="wss-container">
    <ComTabs
      @EventSelectTab="currentSelect"
      :activeName="activeName"
      :tabList="tabList"
    ></ComTabs>
    <div class="main-div">
      <EntityOrg
        v-if="activeName == 'entityOrg' && organizationList.length > 0"
        :organizationList="organizationList"
        :organizationId.sync="organizationId"
      ></EntityOrg>
      <ClientPoints
        v-if="activeName == 'clientPoints' && organizationList.length > 0"
        :organizationList="organizationList"
        :organizationId.sync="organizationId"
      ></ClientPoints>
    </div>
  </main>
</template>

<script>
import ComTabs from "@/wss/components/ComTabs.vue";
import EntityOrg from "./entityOrg/index.vue";
import ClientPoints from "./clientPoints/index.vue";
import { getlabelOrganizationListApi } from "@/wss/newApi_3-24/base/organization.js";

export default {
  components: { EntityOrg, ClientPoints, ComTabs },
  data() {
    return {
      activeName: "entityOrg",
      // tab页数据
      tabList: [
        {
          label: "实体组织",
          name: "entityOrg",
        },
        {
          label: "客户分配",
          name: "clientPoints",
        },
      ],
      // 组织列表
      organizationList: [],
      // 组织id
      organizationId: "",
    };
  },
  async created() {
    // 获取组织列表
    await this.getlabelOrganizationFn();
  },
  methods: {
    // 获取组织列表
    async getlabelOrganizationFn() {
      let { code, rows } = await getlabelOrganizationListApi();
      if (code != 200) return;
      this.organizationList = JSON.parse(JSON.stringify(rows));
      this.organizationId = this.organizationList[0]?.id;
    },
    currentSelect({ label, index, name }) {
      // 表格切换重新
      this.activeName = name;
      this.getlabelOrganizationFn();
    },
  },
};
</script>

<style scoped>
.wss-container {
  display: flex;
  flex-direction: column;
  overflow: initial;
}
.wss-container .el-tabs {
  height: 40px;
  margin-bottom: 20px;
}
.wss-container .main-div {
  height: calc(100% - 60px);
}
</style>